package org.example.springmvc.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * ClassName: Hello08Controller
 * Package: org.example.springmvc.controller
 * Description: 演示保存作用域的使用
 *
 * @Author wanghao
 * @Create 2024-07-11 17:31
 * @Version 1.0
 */
@Controller
@RequestMapping("/hello08")
public class Hello08Controller {

    @RequestMapping("/h01")
    public String h01(HttpServletRequest request){

        request.setAttribute("uname","lisi");
        return "succ02";
    }

    @RequestMapping("/h02")
    public String h02(Model model){  // Model其实是一个Map，但是他的角色就是request属性域

        model.addAttribute("uname","ww");
        return "succ02";
    }

    @RequestMapping("/h03")
    public String h03(ModelMap modelMap){  // ModelMap其实是一个Map，但是他的角色就是request属性域
        modelMap.addAttribute("uname","zs");
        return "succ02";
    }

    @RequestMapping("/h04")
    public String h04(Map map){
        map.put("uname","ll");
        return "succ02";
    }

    @RequestMapping("/h05")
    public ModelAndView h05(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("uname","蘑菇");
        modelAndView.setViewName("succ02");
        return modelAndView;
    }
}
